$(function () {
    getServiceTypeFindAll();
    let id = localStorage.getItem("roomId");
    findByRoomId(id);
});
function getServiceTypeFindAll() {
    let result = myAjax('/back/serviceType/findType','get',{token:$.cookie("token")});
    data = result.list;
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += '<option value="' + data[i].id + '">' + data[i].serviceType + '</option>';
    }
    $("#roomType").html(html);//将页面格式加载到页面布局
}
//拿到数据
function findByRoomId(roomId) {
    let result = myAjax('/back/room/findByRoomId','get',{roomId:roomId,token:$.cookie("token")});
    showData(result.roomModel);
}

//把数据赋值给页面
function showData(data) {
    $("#roomId").val(data.roomId);
    //下拉框根据文本进行赋值*****
    $('#roomType option').filter(function(){return $(this).text()==data.roomType;}).attr("selected",true);
    $("#roomPrice").val(data.roomPrice);
    $("#roomTitle").val(data.roomTitle);
    $("#roomPhoto").val("");
    $("#roomIntroduce").val(data.roomIntroduce);
}

//然后提交改后的数据到后台进行保存，成功后跳转到房间列表界面
function roomEdit() {
    let forData = new FormData();
    forData.append("roomId", $("#roomId").val());
    forData.append("roomType", $("#roomType option:selected").text());
    forData.append("roomPrice", $("#roomPrice").val());
    forData.append("roomTitle", $("#roomTitle").val());
    forData.append("roomPhoto", $("#roomPhoto")[0].files[0]);//文件取值
    forData.append("roomIntroduce", $("#roomIntroduce").val());
    forData.append("token",$.cookie("token"));
    let result = imgMyAjax('/back/room/roomEdit','post',forData);
    if (result.result === 1) {
        alert("提交成功");
        $("#right").load('../back/room/roomList.html');
    } else {
        alert("提交失败")
    }
}
function cancelEdit() {
$("#right").load('/back/room/roomList.html');
}